import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { KingCopyItemData } from "./info/KingCopyItemData";
import { Cache } from "../../../cache/Cache";
import { DirectionCopyConfig } from "../../../resource/DirectionCopyConfig";
import { CopyConfig } from "../../../resource/CopyConfig";
import { MsgManager } from "../../../manager/MsgManager";
import { DropDirectionData } from "./info/DropDirectionData";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ToolTipsManager } from "../../../../../com/mui/manager/ToolTipsManager";
import { KingCopyToolTip } from "../../common/tooltip/KingCopyToolTip";
import { EffectManager } from "../../../manager/EffectManager";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { NpcEffectRule } from "../../../rules/NpcEffectRule";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { ResFileConst } from "../../../resource/ResFileConst";
import { KingCopyItem } from "./KingCopyItem";
import { CloudBg } from "../../consumeCount/CloudBg";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { Vector } from "../../../../../__AS3__/vec/Vector";
type int = number;
//class KingCopyPanel2
    
    export  class KingCopyPanel2 extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.directionArr = new Vector.<flash.display.Sprite>();
            setSize(715, 540);
            titleHeight = 26;
            title = Language.getString(27900);
            return;
        }

        /* internal  */onEnterCopyHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc5=null;
            var loc6=0;
            var loc7=null;
            var loc1=this._copyItemsData[this._curIndex] as KingCopyItemData;
            var loc2=Cache.instance.role.roleInfo.level;
            var loc3=int(Cache.instance.role.combatCapabilities);
            var loc4;
            if (loc4 = DirectionCopyConfig.instance.getItemByFloor(this._curIndex + 1)) 
            {
                if (loc5 = CopyConfig.instance.getInfoByCode(loc4.copyCode)) 
                {
                    loc6 = loc5.enterMinLevel;
                }
                if (loc2 < loc6) 
                {
                    MsgManager.showRollTipsMsg(Language.getStringByParam(27915, loc6));
                    return;
                }
                if (loc3 < loc4.requireCombat) 
                {
                    MsgManager.showRollTipsMsg(Language.getStringByParam(27916, loc4.requireCombat));
                    return;
                }
                if (loc1.copyState == 0) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(27917));
                    return;
                }
            }
            if (this._curDirIndex == -1) 
            {
                MsgManager.showRollTipsMsg(Language.getString(27918));
                return;
            }
            if (loc1 && !(loc1.copyState == 0)) 
            {
                (loc7 = new DropDirectionData()).copyCode = loc1.copyCode;
                loc7.index = this._curDirIndex + 1;
                Dispatcher.dispatchEvent(new DataEvent(EventName.EnterDirectionDropCopy, {"vo": loc7}));
            }
            return;
        }

        /* internal  */onLeftHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!this.isCanDraw) 
            {
                return;
            }
            if (this._curIndex < 5) 
            {
                this._curIndex = (this._curIndex + 1) % 6;
                this.kingCopyItemData = this._curIndex;
                this.dirBtnToolTip = this._curIndex;
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(27919));
            }
            return;
        }

        /* internal  */onRightHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!this.isCanDraw) 
            {
                return;
            }
            if (this._curIndex > 0) 
            {
                this._curIndex = (this._curIndex - 1) % 6;
                this.kingCopyItemData = this._curIndex;
                this.dirBtnToolTip = this._curIndex;
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(27919));
            }
            return;
        }

        /* internal  */set dirBtnToolTip(arg1: int)
        {
            var loc2=null;
            var loc1=this._copyItemsData[arg1] as KingCopyItemData;
            var loc3=0;
            while (loc3 < this.directionArr.length) 
            {
                loc2 = CopyConfig.instance.getKingCopyToolTipData(loc1.copyCode, loc3 + 1);
                ToolTipsManager.unregister(this.directionArr[loc3] as Object /* flash.display.Sprite */);
                ToolTipsManager.register(this.directionArr[loc3] as Object /* flash.display.Sprite */, KingCopyToolTip, loc2);
                ++loc3;
            }
            return;
        }

        /* internal  */onDirSelectHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as Object /* flash.display.Sprite */;
            if (loc1) 
            {
                this._curDirIndex = this.directionArr.indexOf(loc1);
                this.selectState = this._curDirIndex;
            }
            return;
        }

        /* internal  */set selectState(arg1: int)
        {
            var loc1=0;
            while (loc1 < this.directionArr.length) 
            {
                if (loc1 != arg1) 
                {
                    EffectManager.glowFilterUnReg(this.directionArr[loc1]);
                }
                else 
                {
                    EffectManager.glowFilterReg(this.directionArr[loc1], null, 1, 15, 0, int.MAX_VALUE);
                }
                ++loc1;
            }
            return;
        }

        /* internal  */onLoadResHandler(): void
        {
            var loc2=null;
            this._loadCom = true;
            ObjCreate.createBitmap(ImagesConst.KingCopyTitle, 260, 335, this);
            var loc1=0;
            while (loc1 < 5) 
            {
                loc2 = this.createDirectionBtn(loc1 + 1);
                ObjCreate.setObjAttri(loc2, 115 + loc1 * 100, 365, -1, -1, this);
                this.directionArr.push(loc2);
                ++loc1;
            }
            if (this.isCanDraw) 
            {
                this.kingCopyItemData = this._curIndex;
                this.dirBtnToolTip = this._curIndex;
                this.selectState = this._curDirIndex;
            }
            return;
        }

        /* internal  */createDirectionBtn(arg1: int): Object /* flash.display.Sprite */
        {
            var loc1=new Object /* flash.display.Sprite */();
            var loc2=GlobalClass.getBitmap(this.DIRECTION_NAME + arg1);
            loc1.buttonMode = true;
            loc1.addEventListener(flash.events.MouseEvent.CLICK, this.onDirSelectHandler);
            loc1.addChild(loc2);
            return loc1;
        }

        /* internal  */set kingCopyItemData(arg1: int)
        {
            if (arg1 != 0) 
            {
                if (arg1 != 5) 
                {
                    this._leftItem.data = this._copyItemsData[(arg1 - 1)] as KingCopyItemData;
                    this._centreItem.data = this._copyItemsData[arg1] as KingCopyItemData;
                    this._rightItem.data = this._copyItemsData[arg1 + 1] as KingCopyItemData;
                }
                else 
                {
                    this._leftItem.data = this._copyItemsData[(arg1 - 1)] as KingCopyItemData;
                    this._centreItem.data = this._copyItemsData[arg1] as KingCopyItemData;
                    this._rightItem.data = null;
                }
            }
            else 
            {
                this._leftItem.data = null;
                this._centreItem.data = this._copyItemsData[arg1] as KingCopyItemData;
                this._rightItem.data = this._copyItemsData[arg1 + 1] as KingCopyItemData;
            }
            return;
        }

        /* internal  */get isCanDraw(): Boolean
        {
            return this._dataHasGet && this._loadCom;
        }

        public itemData(arg1: Array<any>, arg2: int, arg3: int): void
        {
            this._copyItemsData = arg1;
            this._curIndex = arg2;
            this._curDirIndex = arg3;
            this._dataHasGet = true;
            if (this.isCanDraw) 
            {
                this.kingCopyItemData = this._curIndex;
                this.dirBtnToolTip = this._curIndex;
                this.selectState = this._curDirIndex;
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            NpcEffectRule.registDialogEffectWindow(this);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(18, 38, 679, 290, this);
            var loc1=new GImageBitmap(ImagesConst.KingCopyPanelBg, 18, 38);
            this.addChild(loc1);
            ObjCreate.createBitmap(ImagesConst.RechargeSmallBg, 636, 38, this);
            var loc2=ObjCreate.createBitmap(ImagesConst.RechargeSmallBg, 636, 325, this);
            loc2.scaleY = -1;
            var loc3=ObjCreate.createBitmap(ImagesConst.RechargeSmallBg, 78, 38, this);
            loc3.scaleX = -1;
            var loc4;
            (loc4 = ObjCreate.createBitmap(ImagesConst.RechargeSmallBg, 78, 325, this)).scaleX = -1;
            loc4.scaleY = -1;
            ObjCreate.createBg(10, 300, 250, 1, this, ImagesConst.KillUserLine);
            ObjCreate.createBg(380, 300, 250, 1, this, ImagesConst.KillUserLine);
            var loc5;
            (loc5 = ObjCreate.createGLoadedButton(ResFileConst.KingCopySelectBtn, 26, 140, 48, 33, this)).addEventListener(flash.events.MouseEvent.CLICK, this.onRightHandler);
            var loc6;
            (loc6 = ObjCreate.createGLoadedButton(ResFileConst.KingCopySelectBtn, 685, 170, 48, 33, this)).rotation = 180;
            loc6.addEventListener(flash.events.MouseEvent.CLICK, this.onLeftHandler);
            var loc7;
            (loc7 = ObjCreate.createGLoadedButton(ResFileConst.KingCopyEnterBtn, 303, 278, 97, 42, this)).addEventListener(flash.events.MouseEvent.CLICK, this.onEnterCopyHandler);
            this._leftItem = new KingCopyItem(KingCopyItem.LEFT);
            ObjCreate.setObjAttri(this._leftItem, 82, 80, -1, -1, this);
            this._centreItem = new KingCopyItem(KingCopyItem.CENTER);
            ObjCreate.setObjAttri(this._centreItem, 260, 52, -1, -1, this);
            this._rightItem = new KingCopyItem(KingCopyItem.RIGHT);
            ObjCreate.setObjAttri(this._rightItem, 475, 80, -1, -1, this);
            ObjCreate.createFlowerBg(18, 330, 679, 198, this);
            var loc8=new CloudBg(365);
            ObjCreate.setObjAttri(loc8, 195, 345, -1, -1, this);
            ObjCreate.createBg(30, 470, 658, 2, this, ImagesConst.SplitLine);
            var loc9;
            (loc9 = ObjCreate.createGTextField("", 60, 475, 430, 90, this, GlobalStyle.setTextFormatLeading(GlobalStyle.textFormat1, 5))).multiline = true;
            loc9.wordWrap = true;
            loc9.htmlText = Language.getString(27920);
            ObjCreate.createGTextField(Language.getString(27910), 130, 448, 60, 20, this);
            ObjCreate.createGTextField(Language.getString(27911), 232, 448, 60, 20, this);
            ObjCreate.createGTextField(Language.getString(27912), 332, 448, 60, 20, this);
            ObjCreate.createGTextField(Language.getString(27913), 432, 448, 60, 20, this);
            ObjCreate.createGTextField(Language.getString(27914), 532, 448, 60, 20, this);
            LoaderHelp.addResCallBack(ResFileConst.kingCopy, this.onLoadResHandler);
            return;
        }

        /* internal */ /* const */DIRECTION_NAME: string="KingCopyDropDirection_";

        public static /* const */LEFT_NAME: string="KingCopyLeft_";

        public static /* const */CENTER_NAME: string="KingCopyCenter_";

        public static /* const */RIGHT_NAME: string="KingCopyRight_";

        /* internal */ /* var */_leftItem: KingCopyItem;

        /* internal */ /* var */_centreItem: KingCopyItem;

        /* internal */ /* var */_rightItem: KingCopyItem;

        /* internal */ /* var */directionArr: Vector.<flash.display.Sprite>;

        /* internal */ /* var */_copyItemsData: Array<any>;

        /* internal */ /* var */_curIndex: int;

        /* internal */ /* var */_curDirIndex: int=-1;

        /* internal */ /* var */_dataHasGet: Boolean;

        /* internal */ /* var */_loadCom: Boolean;
    }
